<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglib.jsp" %>    
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script>
	//# sourceURL=orgFunctionTree.js

	var org_setting = {
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		},
        callback: {
            onClick: org_onTreeClick
        }
	};
	
// 	var sel_org_treeNodeId = null;
// 	var sel_org_treeNodeName = null;
	
	function org_onTreeClick(event, treeId, treeNode, clickFlag) {
// 		sel_org_treeNodeId = treeNode.id;
// 		sel_org_treeNodeName = treeNode.name;		
	}

	var org_Nodes = ${listFunction};

	$(document).ready(function(){
		$.fn.zTree.init($("#funcTreeView"), org_setting, org_Nodes);
	});
	
	function btn_ok_click() {
		
		var info = "";
		var treeObj = $.fn.zTree.getZTreeObj("funcTreeView");
		var nodes = treeObj.getCheckedNodes(true);
		
		for (var i=0, L=nodes.length; i<L; i++) {
			info = info + nodes[i].id  + ",";
		}
		
		document.getElementById("relateFuncIds").value=info;
		submitSuccess(info);
	}
	
	function submitSuccess(funcIds) {

		$.post("${ctx}/org/role/${actionName}.action",
			$("#relateFunctionForm").serialize(),
			function(data, status){
				if (data == 'success') {
					dialogSubmitSuccess();
					return;
				} else {
					alert("错误: \n" + data);
				}
			}
		).success(function() { 
			//alert("submitForm success"); 
		})
		.error(function(xmlHttpRequest, textStatus, errorThrown) { 
			  alert("异常： " + xmlHttpRequest.status + ":" + errorThrown);
		})
		.complete(function() { 
			//alert("submitForm complete"); 
		});	

	}	

</script>

</head>

<body>

<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
		&times;
	</button>
	<h4 class="modal-title">关联功能	</h4>
</div>

<div class="modal-body">
	<div>
	<ul id="funcTreeView" class="ztree"></ul>
	<br/>
	</div>

	<form id = "relateFunctionForm">
		<input id="roleId" name="roleId" type="hidden" value="${roleId}"/>
		<input id="relateFuncIds" name="relateFuncIds" type="hidden" value="${relateFuncIds}"/>
	</form>
</div>

<div class="modal-footer">	
	<button type="button" class="btn btn-primary" onclick="btn_ok_click();">确定</button>
	<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>	
</div>
   	
</body>
</html>
